<template>

  <Table :columns="columns" :data="data1"></Table>

</template>


<script type="text/ecmascript-6">
  import api from '@/fetch/api';
  export default {
    beforeMount () {
//      this.customerInfo = JSON.parse(api.getCookie('customerInfo'));
    },
    mounted() {
      this.getList();
    },
    data () {
      return {
        loading: true,
        list: {},
        columns: [
          {
            title: '电影名',
            key: 'title'
          },
          {
            title: '评分',
            key: 'rating'
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.goToDetail(params);
                    }
                  }
                }, '查看'),
              ]);
            }
          }
        ],
        data1: [],
      }
    },
    methods: {
      goBack () {
        this.$router.push({path: '/home'});
      },
      getList () {
        let $this = this;
        let params = {};
        $this.$emit('showLoading');
        api.fetchPost(api.path.in_theaters, params).then((data) => {
          //console.log(JSON.stringify(data));
          $this.$emit('hideLoading');
          data.subjects.forEach(function (e) {
            let item = {
              id: 0,
              title: '',
              rating: '',
            };
            item.id = e.id;
            item.title = e.title;
            item.rating = e.rating.average;
            $this.data1.push(item);
          });
        }).catch(err => {
          $this.$emit('hideLoading');
          this.$Message.error(err);
        })
      },
      goToDetail(params){
        this.$router.push({path: `/movie/detail/${params.row.id}`});
      }
    }
  };
</script>
